import SwiftUI

// 方向控制组件
struct DirectionControlPad: View {
    var onForward: () -> Void
    var onBackward: () -> Void
    var onLeft: () -> Void
    var onRight: () -> Void
    var onStop: () -> Void
    
    var body: some View {
        VStack(spacing: 15) {
            // 前进按钮
            Button(action: onForward) {
                ControlButton(icon: "arrow.up", color: .blue)
            }
            
            HStack(spacing: 15) {
                // 左转按钮
                Button(action: onLeft) {
                    ControlButton(icon: "arrow.left", color: .blue)
                }
                
                // 停止按钮
                Button(action: onStop) {
                    ControlButton(icon: "stop.fill", color: .red)
                }
                
                // 右转按钮
                Button(action: onRight) {
                    ControlButton(icon: "arrow.right", color: .blue)
                }
            }
            
            // 后退按钮
            Button(action: onBackward) {
                ControlButton(icon: "arrow.down", color: .blue)
            }
        }
    }
}

// 控制按钮样式
struct ControlButton: View {
    var icon: String
    var color: Color
    
    var body: some View {
        Image(systemName: icon)
            .font(.system(size: 25))
            .frame(width: 70, height: 70)
            .background(color)
            .foregroundColor(.white)
            .clipShape(Circle())
    }
}

// 状态指示器
struct StatusIndicator: View {
    var icon: String
    var title: String
    var value: String
    var color: Color
    
    var body: some View {
        VStack {
            Image(systemName: icon)
                .font(.system(size: 25))
                .foregroundColor(color)
            
            Text(title)
                .font(.caption)
                .foregroundColor(.secondary)
            
            Text(value)
                .font(.headline)
                .foregroundColor(.primary)
        }
        .frame(width: 100, height: 80)
        .background(Color(.systemGray6))
        .cornerRadius(10)
    }
}

// 速度控制视图
struct SpeedControlView: View {
    var onSpeedUp: () -> Void
    var onSpeedDown: () -> Void
    
    var body: some View {
        HStack(spacing: 30) {
            Button(action: onSpeedDown) {
                SpeedButton(icon: "minus.circle.fill", label: "减速")
            }
            
            Button(action: onSpeedUp) {
                SpeedButton(icon: "plus.circle.fill", label: "加速")
            }
        }
    }
}

// 速度按钮
struct SpeedButton: View {
    var icon: String
    var label: String
    
    var body: some View {
        VStack {
            Image(systemName: icon)
                .font(.system(size: 35))
                .foregroundColor(.blue)
            
            Text(label)
                .font(.caption)
                .foregroundColor(.secondary)
        }
    }
}

// 相机控制视图
struct CameraControlView: View {
    var onTakePhoto: () -> Void
    var onStartVideo: () -> Void
    var onStopVideo: () -> Void
    
    @State private var isRecording = false
    
    var body: some View {
        HStack(spacing: 30) {
            // 拍照按钮
            Button(action: onTakePhoto) {
                VStack {
                    Image(systemName: "camera.fill")
                        .font(.system(size: 30))
                        .foregroundColor(.blue)
                    
                    Text("拍照")
                        .font(.caption)
                }
            }
            
            // 录像按钮
            Button(action: {
                if isRecording {
                    onStopVideo()
                } else {
                    onStartVideo()
                }
                isRecording.toggle()
            }) {
                VStack {
                    Image(systemName: isRecording ? "stop.circle" : "video.fill")
                        .font(.system(size: 30))
                        .foregroundColor(isRecording ? .red : .blue)
                    
                    Text(isRecording ? "停止录像" : "录像")
                        .font(.caption)
                }
            }
        }
    }
}

// 传感器卡片
struct SensorCard: View {
    var icon: String
    var title: String
    var value: String
    var color: Color
    
    var body: some View {
        HStack {
            // 图标
            Image(systemName: icon)
                .font(.system(size: 30))
                .foregroundColor(color)
                .frame(width: 60)
            
            // 标题和数值
            VStack(alignment: .leading) {
                Text(title)
                    .font(.headline)
                    .foregroundColor(.secondary)
                
                Text(value)
                    .font(.title)
                    .fontWeight(.bold)
            }
            
            Spacer()
        }
        .padding()
        .background(Color(.systemGray6))
        .cornerRadius(15)
    }
} 